<template>
    <div class="design clearfloat" >
      <div class="empty" v-if="works.length===0?111:''">
        <i class="iconfont">&#xe639;</i>
        <p>你暂没有发布任何作品</p>
      </div>
        <div class="work_list"  v-for = "(work,index) in works">
            <div class="img">
                <img v-bind:src="'/api/works/'+work.workCover" alt="">
            </div>
            <h5>{{work.workTitle}}</h5>
            <ul class="clearfloat">
                <li>
                    <i class="iconfont">&#xe6e4;</i>{{work.readers}}
                </li>
                <li>
                    <i class="iconfont">&#xe707;</i>{{work.giveLikes.length }}
                </li>
                <li>
                    <i class="iconfont">&#xe6ea;</i>{{work.collections.length}}
                </li>
            </ul>
            <div class="cd">
                <span class="iconfont" v-bind:workId="work._id" @click="delWorkFun">&#xe632;</span>
                <span class="iconfont" v-bind:workId="work._id">&#xe636;</span>
                <span class="fr">{{work.createdAt|filterDate}}</span>
            </div>
        </div>
    </div>
</template>
<script>
import axios from 'axios'
import dataformat from "../../assets/js/dateformat.js"
  export default{
    data(){
      return{
        works:[]
      }
    },
    created:function(){
      this.getWorkList();
    },
    methods:{
      delWorkFun:function(e){
        var that = this;
        var workId  = e.target.getAttribute('workId');
        axios.get('/api/personal/delWork',{
          params:{
            workId:workId,
            userId:that.$store.state.userId
          }
        }).then(function(res){
          if(res.data.ok===1){
              that.getWorkList();
          }
        })
      },
      getWorkList:function(){
        var that = this;
      axios.get('/api/personal/getWorks',{
        params:{
          userId:that.$store.state.userId
        }
      }).then(function(res){
        that.works = res.data;
      })
      }
    },
    filters:{
      filterDate:dataformat
    }
  }
</script>
<style lang="scss" scoped>
.design{
  padding:10px;
}
.empty{
  height:300px;
  text-align: center;
  padding-top:80px;
  i{
    font-size:56px;
    color:#ebebeb; 
  }
  p{
    color:#c7c7c7;
    margin-top:12px;
  }
}
.work_list{
    width:195px;
    float:left;
    margin:20px 10px;
    box-sizing: border-box;
    box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.1);
    .img{
      width:195px;
      height:120px;
      overflow: hidden;
      background: red;
      img{
        min-width:195px;
        min-height:120px;
        max-width:225px;
        max-height:150px;
      }
    }
    h5{
      line-height: 24px;
      padding-left:6px;
      margin-top:6px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
    ul{
      margin-left:6px;
      li{
        font-size:12px;
        margin-right:30px;
        float:left;
        padding-bottom:6px;
        line-height: 20px;
        color:rgb(197, 197, 197);
        span{
          margin-right:4px;
        }
      }
    }
    .cd{
      margin-top:10px;
      margin-bottom:10px;
      .iconfont{
          font-size:15px;
          padding-left:10px;
          color:rgb(204, 204, 204)
        }
        .iconfont:hover{
          color:#007fff;
        }
        .fr{
          font-size:12px;
          color:rgb(197, 197, 197);
          padding-right:10px;
        }
    }
  }
</style>

